<?php
require_once '../common.php';
$query_names = array_key_exists('geneNames', $_REQUEST) ? $_REQUEST['geneNames'] : NULL;
$query_type = array_key_exists('query_type', $_REQUEST) ? $_REQUEST['query_type'] : NULL;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xHTML11/DTD/xHTML11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Block Result</title>
        <style type="text/css">td { border-top: 1px solid black; }</style>
    </head>
    <body>
        <a id="back_home" class="a_back" href="<?php echo SITEURI . '/pages/search.php'; ?>" style="position: fixed; left: 10px; top: 10px;">Homepage</a>
        <?php if (is_null($query_names) || is_null($query_type)) { ?>
        <script type="text/javascript">
            alert("No query keywords were entered. Please try again.");
            window.location.href='search.php';
        </script>
        <?php
        } else {
            require_once ABSPATH . '/class/BlockData.class.php';
            $block_service = new BlockData();
            $array_block_id = $block_service->get_block_id($query_names);
            if (!is_null($array_block_id) && count($array_block_id) > 0) {
                foreach ($array_block_id as $block_id) {
                    if (!$block_service->block_exists($block_id))
                        continue;
                    $img_src = SITEURI . '/data/blockImages/' . $block_id . '.png';
                    $block_info_basic = $block_service->get_block_info_basic($block_id);
                    $block_info_enrichment_a = $block_service->get_block_info_enrichment($block_id, 0);
                    $block_info_enrichment_q = $block_service->get_block_info_enrichment($block_id, 1);
        ?>
        
        <div>
            <table>
                <tbody>
                    <tr>
                        <td width="40%"><a href="<?php echo $img_src; ?>"><img src="<?php echo $img_src; ?>" alt="<?php echo $block_id . '.png'; ?>" /></a></td>
                        <td width="60%"> S.No. <b><?php echo $block_info_basic['id']; ?></b><br /> Clique index = <?php echo $block_info_basic['aq']; ?><br /> Interaction density = <?php echo $block_info_basic['interaction_density'];?>
                            <table>
                                <tbody>
                                    <tr></tr>
                                    <tr></tr>
                                    <tr></tr>
                                    <tr>
                                        <td width="50%"><b>Array genes</b></td>
                                        <td width="50%"><b>Query genes</b></td>
                                    </tr>
                                    <tr>
                                        <td> Global profile corr = <?php echo $block_info_basic['corr_coef_a']; ?></td>
                                        <td> Global profile corr = <?php echo $block_info_basic['corr_coef_q']; ?></td>
                                    </tr>
                                    <tr>
                                        <td><b>Process Enrichments</b></td>
                                        <td><b>Process Enrichments</b></td>
                                    </tr>
                                    <tr>
                                        <td>
                                        <?php 
                                        if (!is_null($block_info_basic['process_enrichment_a'])){
                                            $array_pe_a = explode('|', $block_info_basic['process_enrichment_a']);
                                            foreach ($array_pe_a as $pe_a){
                                                $pe_a = trim($pe_a);
                                                if (strlen($pe_a) == 0) continue;
                                        ?>
                                             - <?php echo $pe_a; ?><br />
                                        <?php
                                            }
                                        }
                                        ?>
                                        </td>
                                        <td>
                                        <?php 
                                        if (!is_null($block_info_basic['process_enrichment_q'])){
                                            $array_pe_q = explode('|', $block_info_basic['process_enrichment_q']);
                                            foreach ($array_pe_q as $pe_q){
                                                $pe_q = trim($pe_q);
                                                if (strlen($pe_q) == 0) continue;
                                        ?>
                                             - <?php echo $pe_q; ?><br />
                                        <?php
                                            }
                                        }
                                        ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><b>Enrichments</b></td>
                                        <td><b>Enrichments</b></td>
                                    </tr>
                                    <tr>
                                        <td><?php 
                                        if (!is_null($block_info_enrichment_a) && count($block_info_enrichment_a) > 0){
                                            foreach ($block_info_enrichment_a as $enrichment_a){
                                        ?>
                                            - <?php echo $enrichment_a['enrichment']; ?> <br/>
                                        <?php
                                        } }
                                        ?> - </td>
                                        <td><?php 
                                        if (!is_null($block_info_enrichment_q) && count($block_info_enrichment_q) > 0){
                                            foreach ($block_info_enrichment_q as $enrichment_q){
                                        ?>
                                            - <?php echo $enrichment_q['enrichment']; ?> <br/>
                                        <?php
                                        } }
                                        ?> - </td>
                                    </tr>
                                    <tr>
                                        <td><b>OMIM disease</b></td>
                                        <td><b>OMIM disease</b></td>
                                    </tr>
                                    <tr>
                                        <td>
                                        <?php 
                                        if (!is_null($block_info_basic['disease_genes_a'])){
                                            $array_dg_a = explode('|', $block_info_basic['disease_genes_a']);
                                            foreach ($array_dg_a as $dg_a){
                                                $dg_a = trim($dg_a);
                                                if (strlen($dg_a) == 0) continue;
                                        ?>
                                             - <?php echo $dg_a; ?><br />
                                        <?php
                                            }
                                        }
                                        ?>
                                        </td>
                                        <td>
                                        <?php 
                                        if (!is_null($block_info_basic['disease_genes_q'])){
                                            $array_dg_q = explode('|', $block_info_basic['disease_genes_q']);
                                            foreach ($array_dg_q as $dg_q){
                                                $dg_q = trim($dg_q);
                                                if (strlen($dg_q) == 0) continue;
                                        ?>
                                             - <?php echo $dg_q; ?><br />
                                        <?php
                                            }
                                        }
                                        ?>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <?php
                }
            }
        }
        ?>
    </body>
</html>